<?php

/**
 * This is the model class for table "tb_ua".
 *
 * The followings are the available columns in table 'tb_ua':
 * @property integer $ID_UA
 * @property string $NUM_UA
 * @property integer $PALLET_UA
 * @property string $DT_ENTRADA_UA
 * @property string $DT_ENVIO_UA
 * @property string $DT_SAIDA_UA
 * @property integer $TB_MERCADORIA_ID_MERCADORIA
 * @property integer $TB_SERVICO_ID_SERVICO
 *
 * The followings are the available model relations:
 * @property TbProcesso[] $tbProcessos
 * @property TbMercadoria $tBMERCADORIAIDMERCADORIA
 * @property TbServico $tBSERVICOIDSERVICO
 */
class Ua extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Ua the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tb_ua';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('NUM_UA, PALLET_UA, DT_ENTRADA_UA, DT_ENVIO_UA, TB_MERCADORIA_ID_MERCADORIA, TB_SERVICO_ID_SERVICO', 'required'),
			array('PALLET_UA, TB_MERCADORIA_ID_MERCADORIA, TB_SERVICO_ID_SERVICO', 'numerical', 'integerOnly'=>true),
			array('NUM_UA', 'length', 'max'=>255),
			array('DT_SAIDA_UA', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('ID_UA, NUM_UA, PALLET_UA, DT_ENTRADA_UA, DT_ENVIO_UA, DT_SAIDA_UA, TB_MERCADORIA_ID_MERCADORIA, TB_SERVICO_ID_SERVICO', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'tbProcessos' => array(self::HAS_MANY, 'TbProcesso', 'TB_UA_ID_UA'),
			'tBMERCADORIAIDMERCADORIA' => array(self::BELONGS_TO, 'TbMercadoria', 'TB_MERCADORIA_ID_MERCADORIA'),
			'tBSERVICOIDSERVICO' => array(self::BELONGS_TO, 'TbServico', 'TB_SERVICO_ID_SERVICO'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'ID_UA' => 'Id Ua',
			'NUM_UA' => 'Num Ua',
			'PALLET_UA' => 'Pallet Ua',
			'DT_ENTRADA_UA' => 'Dt Entrada Ua',
			'DT_ENVIO_UA' => 'Dt Envio Ua',
			'DT_SAIDA_UA' => 'Dt Saida Ua',
			'TB_MERCADORIA_ID_MERCADORIA' => 'Tb Mercadoria Id Mercadoria',
			'TB_SERVICO_ID_SERVICO' => 'Tb Servico Id Servico',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('ID_UA',$this->ID_UA);
		$criteria->compare('NUM_UA',$this->NUM_UA,true);
		$criteria->compare('PALLET_UA',$this->PALLET_UA);
		$criteria->compare('DT_ENTRADA_UA',$this->DT_ENTRADA_UA,true);
		$criteria->compare('DT_ENVIO_UA',$this->DT_ENVIO_UA,true);
		$criteria->compare('DT_SAIDA_UA',$this->DT_SAIDA_UA,true);
		$criteria->compare('TB_MERCADORIA_ID_MERCADORIA',$this->TB_MERCADORIA_ID_MERCADORIA);
		$criteria->compare('TB_SERVICO_ID_SERVICO',$this->TB_SERVICO_ID_SERVICO);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}